package com.lcm.oj.lanqiao.year2021.moni.demo;

/**
 * @author Coder-lcm
 * @date 2021/4/17
 */
public class GcbLcm {
    public static void main(String[] args) {
        System.out.println(gcb(12,8));
        System.out.println(lcm(13,8));
    }

    /**
     * 求两个数的最大公因数
     * @param n1
     * @param n2
     * @return
     */
    public static int gcb(int n1, int n2) {
        return n2 == 0 ? n1 : gcb(n2, n1 % n2);
    }

    /**
     * 求最小公倍数
     * @param n1
     * @param n2
     * @return
     */
    public static int lcm(int n1, int n2) {
        int gcb = gcb(n1, n2);
        return (n1 / gcb) * (n2 / gcb) * gcb;
    }
}
